//
//  CSYBottomView.swift
//  CSYMicroBlockSina
//
//  Created by 姚彦兆 on 15/11/15.
//  Copyright © 2015年 姚彦兆. All rights reserved.
//

import UIKit
import SnapKit
class CSYBottomView: UIView {
    
    @objc func clickRetweetedButton(){
    
        let nav = CSYDoRetweedController()
        
        retweetedBtn.getNavController()?.pushViewController(nav,animated: true)
    
    }
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setUpUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置UI
    private func setUpUI(){
        
        let topLine = cutLine()

        addSubview(topLine)
        
        topLine.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(snp_top)
            
            make.width.equalTo(snp_width).offset(-10.0)
            
            make.centerX.equalTo(snp_centerX)
            
            make.height.equalTo(lineWidth)
            
        }
        
        //添加转发按钮
        addSubview(retweetedBtn)
        
        //添加约束
        retweetedBtn.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(snp_top)
            
            make.left.equalTo(snp_left)
            
            make.height.equalTo(snp_height)
            
        }
        
        retweetedBtn.addTarget(self, action: "clickRetweetedButton", forControlEvents: .TouchUpInside)
        
        let cutLine1 = cutLine()
        
        addSubview(cutLine1)
        
        cutLine1.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(retweetedBtn.snp_right)
            
            make.width.equalTo(lineWidth)
            
            make.centerY.equalTo(snp_centerY)
            
            make.height.equalTo(snp_height).multipliedBy(scale)
            
        }
        
        addSubview(composeBtn)
        
        composeBtn.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(retweetedBtn.snp_top)
            
            make.left.equalTo(retweetedBtn.snp_right)
            
            make.height.equalTo(snp_height)
            
            make.width.equalTo(retweetedBtn.snp_width)
            
        }
        
        let cutLine2 = cutLine()
        
        addSubview(cutLine2)
        
        cutLine2.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(composeBtn.snp_right)
            
            make.width.equalTo(lineWidth)
            
            make.centerY.equalTo(snp_centerY)
            
            make.height.equalTo(snp_height).multipliedBy(scale)
            
        }

        
        addSubview(likeBtn)
        
        likeBtn.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(composeBtn.snp_right)
            
            make.top.equalTo(composeBtn)
            
            make.right.equalTo(snp_right)
            
            make.height.equalTo(snp_height)
            
            make.width.equalTo(composeBtn.snp_width)
            
        }
        
        let bottomLine = cutLine()
        
        addSubview(bottomLine)
        
        bottomLine.snp_makeConstraints { (make) -> Void in
            
            make.bottom.equalTo(snp_bottom)
            
            make.width.equalTo(snp_width).offset(-10.0)
            
            make.centerX.equalTo(snp_centerX)
            
            make.height.equalTo(lineWidth)
            
        }

        
        
    }
    
    //分割线
    private func cutLine () -> UIView {
        
        let lineView = UIView()
        
        lineView.backgroundColor = UIColor.lightGrayColor()
        
        return lineView
        
    }
    
    //懒加载所有控件
    lazy var retweetedBtn : UIButton = UIButton(title: "转发", titleColor: UIColor.lightGrayColor(), image: "timeline_icon_retweet", backImage: nil, fontSize: 12)
    
    lazy var composeBtn : UIButton = UIButton(title: "评论", titleColor: UIColor.lightGrayColor(), image: "timeline_icon_comment", backImage: nil, fontSize: 12)
    
    lazy var likeBtn : UIButton = UIButton(title: "赞", titleColor: UIColor.orangeColor(), image: "timeline_icon_like", backImage: nil, fontSize: 12)
    
}
